package com.sangmo.fts.process.storage.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

@Entity
@Table(name = "csf_draft")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class CsfDraft extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50, index = true, unique = true)
    private String code;

    @One(value = "loan", target = CsfLoan.class, groups = {"CsfDraft.search","CsfDraft.detail","CsfDraft.selection"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long loanId;

    /** 出票人 **/
    @One(value = "drawerCompany", target = Company.class, fieldset = {"id","name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long drawerId;

    /** 收款人 **/
    @One(value = "payeeCompany", target = Company.class, fieldset = {"id","name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long payeeId;

    @DataField(value = IConstants.DATA_TYPE.DECIMAL_POSITIVE_MONEY, required = true)
    private BigDecimal amount;

    @DataField(value = IConstants.DATA_TYPE.DATE, required = true)
    private Date issueDate;

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long bankId;

    @DataField(value = IConstants.DATA_TYPE.DECIMAL_POSITIVE_MONEY, required = true)
    private BigDecimal fee;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getLoanId() {
        return loanId;
    }

    public void setLoanId(Long loanId) {
        this.loanId = loanId;
    }

    public Long getDrawerId() {
        return drawerId;
    }

    public void setDrawerId(Long drawerId) {
        this.drawerId = drawerId;
    }

    public Long getPayeeId() {
        return payeeId;
    }

    public void setPayeeId(Long payeeId) {
        this.payeeId = payeeId;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public Date getIssueDate() {
        return issueDate;
    }

    public void setIssueDate(Date issueDate) {
        this.issueDate = issueDate;
    }

    public Long getBankId() {
        return bankId;
    }

    public void setBankId(Long bankId) {
        this.bankId = bankId;
    }

    public BigDecimal getFee() {
        return fee;
    }

    public void setFee(BigDecimal fee) {
        this.fee = fee;
    }
}
